home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / trncod.arc / RTNCODE.C < prev    next >
Encoding:
Text File  |  1986-12-31  |  2.4 KB  |  102 lines

  1. /* RTNCODE.C ** Program to allow other programs to return an ERRORLEVEL
  2.         to Batch files. Specifically applicable for those programming
  3.         language that don't support the return code facility of DOS.
  4.         The requirement here is that the language supports the ability
  5.         to poke bytes into memory.
  6.                             -- R.D.Allen, 12/30/86
  7.  
  8. Instructions: The value of the byte at Segment 40h, Offset ffh, will be used
  9.     as the return code back to the original process (like a Batch file).
  10.     The only reserved values are 0 and 255. 0 is good status, 255 is
  11.     failure.
  12.  
  13.     0040:00ff is a "safe" value as it is in the inter-program 
  14.     communication area (ICA) as allowed for by DOS (promise).
  15.  
  16.     So instead of having in your ".bat" file.....
  17.  
  18. myprog input1 input2 input3
  19.  
  20.     .....you install....
  21.  
  22. rtncode myprog input_1 input_2 input_3
  23.  
  24.     .... and you use pokes to 40:00ff to assure the return code
  25.     value.
  26.  
  27.  
  28.     FREE TO USE BUT NOT TO PROFIT!
  29.     Stelson Products Company
  30.     1625 Travis, Garland, TX 75042
  31. */
  32.  
  33. /* Compiled with Lattice 3.1 library */
  34.  
  35. void prn_long(char *, long);
  36. void mk_title();
  37.  
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40.  
  41. /*********
  42. *    NAME:    MY_TITLE
  43. *     USE:      Make a title and store it in Blurb global. This string
  44. *        should be output before all print lines to identify the
  45. *        author marks and program name.
  46. *   INPUT:      char    *string;     -- pointer to argv[0]
  47. *  OUTPUT:      nothing
  48. *********/
  49.  
  50. char Blurb[24];
  51.  
  52. void my_title(string)
  53. char    *string;
  54. {
  55. char    node[12];
  56. char    *strchr();
  57.  
  58.     stcgfn(node, string);
  59.     *strchr(node, '.') = '\0';
  60.     sprintf(Blurb, "SPC-%s> ", node);
  61. }
  62.  
  63. /*********
  64. *    NAME:    MAIN
  65. *     USE:      Using the command line passed, fork using the command
  66. *        line as the arguments. Look in the special place for the
  67. *        return code.
  68. *   INPUT:      
  69. *  OUTPUT:      
  70. *********/
  71.  
  72. #define    SEGMENT    (unsigned int)0x40
  73. #define OFFSET    (unsigned int)0xff
  74.  
  75. void main(argc, argv)
  76. int    argc;
  77. char    **argv;
  78. {
  79. int    error, rtn;
  80. char    byte;
  81.  
  82.     my_title(argv[0]);
  83.  
  84.     byte = 0;
  85.     poke(SEGMENT, OFFSET, &byte, 1);
  86.  
  87.     error = forkvp(argv[1], &argv[1]);
  88.     rtn = wait();
  89.  
  90.     if(error == -1) {
  91.         poserr(Blurb);
  92.         byte = 0xff;
  93.     }
  94.     else {
  95.         peek(SEGMENT, OFFSET, &byte, 1);
  96.         printf("%sReturn code was %d, now %d\n", 
  97.             Blurb, rtn & 0xff, (int) byte);
  98.     }
  99.  
  100.     exit((int)byte);
  101. }
  102.